package one.bugu.android.demon.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.*;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import one.bugu.android.demon.R;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Date: 2017/9/22
 * Time: 17:22
 * Description: show at Http requesting
 */
public class DialogShare extends Dialog {


    private Context mContext;
    private TextView titleTextView;
    private Button cancelBtn;
    private LinearLayout contentLayout;
    private OnDialogVersionListener onDialogVersionListener;
    private int shareType = -1;
    private boolean isSHowTitle = false;

    public DialogShare(Context context) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        initView();
    }

    public DialogShare(Context context, int shareType, boolean isSHowTitle) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        this.shareType = shareType;
        this.isSHowTitle = isSHowTitle;
        initView();
    }

    private void initView() {
        View view = null;
        if (shareType == -1) {
            view = LayoutInflater.from(mContext).inflate(R.layout.dialog_share, null);
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.dialog_snatch_share, null);
            View ll_share_title = view.findViewById(R.id.ll_share_title);
            ll_share_title.setVisibility(isSHowTitle ? View.VISIBLE : View.GONE);
        }
        setContentView(view);
        cancelBtn = view.findViewById(R.id.negativeButton);
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager wm = this.getWindow().getWindowManager();
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        lp.width = width;
        dialogWindow.setAttributes(lp);
        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        view.findViewById(R.id.layout_one).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogVersionListener != null) {
                    onDialogVersionListener.onSure("1");
                }
                dismiss();
            }
        });
        view.findViewById(R.id.layout_two).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogVersionListener != null) {
                    onDialogVersionListener.onSure("2");
                }
                dismiss();
            }
        });
        view.findViewById(R.id.layout_three).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogVersionListener != null) {
                    onDialogVersionListener.onSure("3");
                }
                dismiss();
            }
        });
    }

    public OnDialogVersionListener getOnDialogVersionListener() {
        return onDialogVersionListener;
    }

    public void setOnDialogVersionListener(OnDialogVersionListener onDialogVersionListener) {
        this.onDialogVersionListener = onDialogVersionListener;
    }

    public interface OnDialogVersionListener {
        void onSure(String string);
    }


}
